﻿using System;
using GeoAPI.Geometries;
using NetTopologySuite.Geometries;

namespace NetTopologySuite.Shape
{
	public abstract class GeometricShapeBuilder
	{
		protected GeometricShapeBuilder(IGeometryFactory geomFactory)
		{
			this.GeomFactory = geomFactory;
		}

		public Envelope Extent
		{
			get
			{
				return this._extent;
			}
			set
			{
				this._extent = value;
			}
		}

		public Coordinate Centre
		{
			get
			{
				return this._extent.Centre;
			}
		}

		public double Diameter
		{
			get
			{
				return System.Math.Min(this._extent.Height, this._extent.Width);
			}
		}

		public double Radius
		{
			get
			{
				return this.Diameter * 0.5;
			}
		}

		public LineSegment GetSquareBaseLine()
		{
			double radius = this.Radius;
			Coordinate centre = this.Centre;
			Coordinate p = new Coordinate(centre.X - radius, centre.Y - radius);
			Coordinate p2 = new Coordinate(centre.X + radius, centre.Y - radius);
			return new LineSegment(p, p2);
		}

		public Envelope GetSquareExtent()
		{
			double radius = this.Radius;
			Coordinate centre = this.Centre;
			return new Envelope(centre.X - radius, centre.X + radius, centre.Y - radius, centre.Y + radius);
		}

		public int NumPoints { get; set; }

		public abstract IGeometry GetGeometry();

		protected Coordinate CreateCoord(double x, double y)
		{
			Coordinate coordinate = new Coordinate(x, y);
			this.GeomFactory.PrecisionModel.MakePrecise(coordinate);
			return coordinate;
		}

		private Envelope _extent = new Envelope(0.0, 1.0, 0.0, 1.0);

		protected IGeometryFactory GeomFactory;
	}
}
